//go:build windows
// +build windows

package citools

import (
	"fmt"
	"os"
	"os/exec"
	"syscall"
)

//func Command(cmdstr string) (err error) {
//	session := sh.NewSession()
//	//session.ShowCMD = true
//	fmt.Println(cmdstr)
//	if runtime.GOOS == "windows" {
//		err = session.Command("CMD", "/C", cmdstr).Run()
//	} else {
//		err = session.Command("bash", "-c", cmdstr).Run()
//	}
//	return err
//}

func Command(cmdstr string) (err error) {
	//session.ShowCMD = true
	fmt.Println(cmdstr)
	var gocmd *exec.Cmd
	gocmd = exec.Command("CMD", "/C", cmdstr)
	//  核心点,直接修改执行命令方式
	gocmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: fmt.Sprintf(`/c %s`, cmdstr), HideWindow: true}

	gocmd.Stdout = os.Stdout
	gocmd.Stderr = os.Stderr
	return gocmd.Run()
}
